﻿Imports System.ComponentModel

Public Class ButtonRichTextEditExt
    Inherits ButtonEdit
    Implements IDisposable

    Shared Sub New()
        RepositoryItemButtonRichTextEditExt.Register()
    End Sub
    Public Sub New()
    End Sub

    Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
        MyBase.OnKeyDown(e)
    End Sub
    Protected Overrides Sub OnEnter(ByVal e As EventArgs)
        MyBase.OnEnter(e)
    End Sub
    Public Overrides ReadOnly Property EditorTypeName() As String
        Get
            Return RepositoryItemButtonRichTextEditExt.EditorName
        End Get
    End Property

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Shadows ReadOnly Property Properties() As RepositoryItemButtonRichTextEditExt
        Get
            Return TryCast(MyBase.Properties, RepositoryItemButtonRichTextEditExt)
        End Get
    End Property

    Protected Overrides Sub OnClickButton(ByVal buttonInfo As DevExpress.XtraEditors.Drawing.EditorButtonObjectInfoArgs)
        ShowPopupForm()
        MyBase.OnClickButton(buttonInfo)
    End Sub
    Protected Overridable Sub ShowPopupForm()
        Try
            Me.Cursor = Cursors.WaitCursor
            Using form As New RichTextEditExtForm()
                If Me.EditValue IsNot Nothing Then
                    'form.HTMLText = Me.EditValue.ToString
                    form.RTFText = Me.EditValue.ToString()
                End If
                form.StartPosition = FormStartPosition.CenterParent
                'form.Location = Me.PointToScreen(New Point(0, Height))
                Me.Cursor = Cursors.Default
                If form.ShowDialog() = DialogResult.OK Then
                    Me.EditValue = form.RTFText
                End If
            End Using
        Catch ex As Exception
            MessageWindow.ShowMessage(ex)
        Finally
            Me.Cursor = Cursors.Default

        End Try
    End Sub
End Class
